package com.minelx.statementplus.ui.form.ui.memberbased.addingfield;

import com.minelx.sqlstructures.core.database.IDatabase;
import com.minelx.sqlstructures.core.table.ITable;
import com.minelx.sqlstructures.core.values.FieldValues;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import static java.util.stream.Collectors.toList;

// FIXME 2021/8/21  NEEDED TEST SUPPORT!
public class LimitedDatabase implements IDatabase {
	private final IDatabase decorated;

	private final Collection<String> limitation;

	public LimitedDatabase(IDatabase decorated, Collection<String> limitation) {
		this.decorated = decorated;
		this.limitation = limitation;
	}

	@Override
	public ITable table(String s) {
		if (!limitation.contains(s)) {
			throw new UnsupportedOperationException("operation is unsupported.");
		}
		return decorated.table(s);
	}

	@Override
	public ITable createTable(String s, List<FieldValues> list) {
		return decorated.createTable(s, list);
	}

	@Override
	public List<ITable> getTables() {
		return limitation.stream().map(this::table).collect(toList());
	}

	@Override
	public String getName() {
		return decorated.getName();
	}

	@Override
	public void clear() {
		decorated.clear();
	}
}
